<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件处理</title>
    <style>
        .container{
            width: 200px;
            height: 200px;
            padding: 5%;
            background-color: skyblue;
        }

        button {
            margin: 2px;
        }
    </style>
    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>
</head>

<body>
    <div id="app"></div>
    <script type="text/babel">
        class EventDemo extends React.Component{
            render(){
                return (
                    <div className="container" onClick={this.rootClockCallback}>
                        <button onClick={this.printMessage1}>Button_No.1</button>
                        <button onClick={this.printMessage2}>Button_No.2</button>
                    </div>
                )
            }

            rootClockCallback = () => {
                console.log('Root_ClickCallback_Triggered', event)
            }
            
            /*
                1. React 事件对象是由 React 封装过的自定义类对象.
                2. 该对象上绑定了同原生事件对象同样的属性，但是只有要用到的属性被赋予了值。
                2. 因此当需要调用事件对象的属性和方法时，直接像原生事件对象一样调用即可
            */
            printMessage1 = (event) => {
                event.stopPropagation(); // 阻止冒泡，rootClockCallback 不会被调用
                console.log('Message_PrinterNo.1_triggered');
            }

            printMessage2 = () => {
                console.log('Message_PrinterNo.2_triggered');
            }
        }

        ReactDOM.render(<EventDemo/>, document.querySelector('#app'))
    </script>
</body>

</html>